package com.elasticsearch.controller;

import com.elasticsearch.model.Project;
import com.elasticsearch.service.ProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author chong
 * @create 2020/3/24
 * Desc:
 */
@RestController
public class ProjectController {

    @Autowired
    private ProjectService projectService;

    /**
     * es 入数据
     * @return
     */
    @GetMapping("/saveProAll")
    public Map<String,Object> saveAll(){
        Map<String,Object> map = new HashMap<>();
        map.put("success", true);
        try {
            List<Project> all = projectService.findAll();
            projectService.savaAll(all);
        } catch (Exception e) {
            map.put("success", false);
        }
        return map;
    }

    /**
     * 根据编号查询
     * @param proCode
     * @return
     */
    @PostMapping("/findAllByProCode")
    public Map<String,Object> saveAll(@RequestBody String proCode){
        Map<String,Object> map = new HashMap<>();
        map.put("success", true);
        try {
            List<Project> all = projectService.findAllByProCode(proCode);
            map.put("data",all);
        } catch (Exception e) {
            map.put("success", false);
        }
        return map;
    }
}
